# converters/deb.py
import subprocess

class DebConverter:
    def __init__(self, log_callback, dependency_map):
        self.log = log_callback
        self.dependency_map = dependency_map

    def convert(self, wsl_file_path, temp_dir):
        """转换 .deb 包"""
        self.log("开始转换 .deb 包...\n")
        cmd = f'wsl ll-convert-deb "{wsl_file_path}" --output {temp_dir}/linglong'
        self._run_wsl_command(cmd)

    def _run_wsl_command(self, cmd):
        """执行 WSL 命令并实时输出日志"""
        process = subprocess.Popen(
            cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True
        )
        for line in process.stdout:
            self.log(line)
        process.wait()
        if process.returncode != 0:
            raise subprocess.CalledProcessError(process.returncode, cmd)